import instance from '@/utils/axios.js';
//列表获取
function getChannels (){
    return instance({
        url:'/v1_0/channels',
        method:'get'
    })
}

export {getChannels}
// 文章获取
function getArticleList({channel_id,timestamp}){
    return instance({
        url:'/v1_1/articles',
        method:'get',
        params:{
            channel_id,
            timestamp,
            with_top:1
        }
    })
}
export {getArticleList}



/* 3.获取文章详细信息 */
function getArticleInfo(id){
    return instance({
        /* 这个接口的参数就是文章id，直接在路径后面写、  格式:  url/id */
        url:`/v1_0/articles/${id}`,
        method:'get',
    })
}
export {getArticleInfo}
 
//4.关注用户
const followUser = ({target}) => {
    return instance({
      url: '/v1_0/user/followings',
      method: 'post',
      data:{target}
    })
  }
  
  //5.取消用户
  const unFollowUser = ({target}) => {
    return instance({
      //这个接口的id直接在路径后面拼接  格式： url/target
      url: `/v1_0/user/followings/${target}`,
      method: 'delete',
    })
  }
  //导出接口
  export { followUser,unFollowUser }



  //搜索关键词
  function getSuggestion({q}){
    return instance({
        url:`/v1_0/suggestion`,
        method:'get',
        params:{q}
    })
}
  //导出接口
  export { getSuggestion }



//文章的点赞
function addPraise({target}){
    return instance({
        url:'/v1_0/article/likings',
        method:'post',
            data:{target}
    })
}
export{addPraise}
/* 取消点赞 */
function deletePraise(target){//let target = 123456
    return instance({
        /* 这个接口的参数就是用户id，直接在路径后面写、  格式:  url/id */
        url:`/v1_0/article/likings/${target}`,
        method:'delete',
    })
}
export {deletePraise}


//对文章的不喜欢
const dislike=({target})=>{
    return instance({
        method:'post',
        url:'/v1_0/article/dislikes',
        data:{target}
    })
}
export {dislike}



//取消对文章的不喜欢
const noDislike=({target})=>{
    return instance({
        /* 这个接口的参数就是用户id，直接在路径后面写、  格式:  url/id */
        url:`/v1_0/article/dislikes/${target}`,
        method:'delete',
    })
}
export {noDislike}

//搜索结果
function getSearch(params){
    return instance({
        method:'get',
        url: '/v1_0/search',
        params
    })
}
export {getSearch}

//搜索历史
function getSearchHistory(){
    return instance({
        method:'get',
        url: '/v1_0/search/histories',
    })
}
export {getSearchHistory}

//搜索历史
function deleteSearchHistory(){
    return instance({
        method:'delete',
        url: '/v1_0/search/histories',
    })
}
export {deleteSearchHistory}
